#include "animatewindowpath.h"
#include <QPainter>
#include <QDebug>
#include <QScreen>
#include <QApplication>

AnimateWindowPath::AnimateWindowPath()
{
    setAttribute( Qt::WA_TranslucentBackground, true );
    resize(110, 110);

    QRegion window( 0,
                    0,
                    width(),
                    height(),
                    QRegion::Rectangle );

    QRegion mouseHole(
                       width() / 2 - 1,
                       height() / 2 - 1,
                       2,
                       2,
                       QRegion::Rectangle );

    QRegion r1 = window.QRegion::subtracted( mouseHole );
    this->setMask( r1 );
}

AnimateWindowPath::~AnimateWindowPath()
{
}

void AnimateWindowPath::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setPen(Qt::red);
    painter.setBrush(Qt::red);

    for (int i = 0; i < trailPoints.size() - 1; ++i)
    {
        painter.drawLine(mapFromGlobal(trailPoints[i]), mapFromGlobal(trailPoints[i + 1]));
    }
}

void AnimateWindowPath::setRadiusColor( int valueDiameter, QColor valueColor )
{
    diameter = valueDiameter;
    color = valueColor;
    repaint();
}

void AnimateWindowPath::setOpacity( double value )
{
    opacity = value;
}

void AnimateWindowPath::setRadiant( bool value )
{
    radiant = value;
}

void AnimateWindowPath::addTrailPoint(const QPoint &point)
{
    trailPoints.append(point);
    if (trailPoints.size() > maxTrailLength) {
        trailPoints.pop_front();
    }

    update();
}

